import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_shop/cons/global_cons.dart';
import 'package:flutter_shop/pages/home/home_router.dart';
import 'package:flutter_shop/pages/home/home_tab_page/entity/home_content_data.dart';
import 'package:flutter_shop/routers/navigator_utils.dart';
import 'package:flutter_shop/widget/load_image.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

///顶部banner
class TopBanner extends StatelessWidget {
  final List<HomeContentDataSlide> slides;
  double height;

  TopBanner({Key key, @required this.slides, this.height}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: ScreenUtil.screenWidthDp,
      height: height ?? ScreenUtil().setHeight(333),
      child: Swiper(
        itemCount: slides.length,
        itemBuilder: (context, index) => LoadImage(
          slides[index].image,
          fit: BoxFit.cover,
        ),
        autoplay: true,
        pagination: SwiperPagination(),
        onTap: (index) {
          HomeContentDataSlide item = slides[index];
          NavigatorUtils.push(context, HomeRouter.goodDetail, params: {GlobalCons.KEY_ID: item.goodsId});
        },
      ),
    );
  }
}
